﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var _type = "", _typeid="";
    $(function () {
        InitialPage();
        GetTree();      
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载树
    function GetTree() {
        var item = {
            height: $(window).height() - 55.5,
            url: "../../FinancialManage/FeeItems/GetTreeList",
            onnodeclick: function (item) {
                if (item.Type != "0") {
                    _type = item.Type;
                    _typeid = item.id;
                    SearchEvent();
                }
            }
        };       
        $("#itemTree").treeview(item);
    }

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../FinancialManage/FeeItems/GetPageListJson",
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'Id', hidden: true },
                { label: "费项名称", name: "Name", width: 100, align: "left", sortable: false },
                { label: "费项编号", name: "Code", width: 100, align: "left", sortable: false },
                {
                    label: "计费方式", name: "CalType", width: 60, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {                        
                        return cellvalue == "1" ? "周期性" : cellvalue == "2" ? "临时性":cellvalue == "3" ? "滞纳金":"";
                    }
                },
                {
                    label: "统计类别", name: "StatiscalCategoryId", width: 120, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                       
                        return cellvalue != null ? top.clientdataItem.StatiscalCategory[cellvalue] : "";
                       }
                },
                { label: "计算方法", name: "CalculateType", width: 150, align: "center", sortable: false },                
                { label: "用量公式", name: "QuantityFormula", width: 100, align: "center", sortable: false },
                { label: "系数公式", name: "CoefficientFormula", width: 100, align: "left", sortable: false },
                { label: "单价公式", name: "UnitPriceFormula", width: 100, align: "left", sortable: false },
                //{ label: "费项性质", name: "PropertyTypeId", width: 100, align: "left", sortable: false },
                //{ label: "税务项目", name: "TaxItemId", width: 100, align: "left", sortable: false },
                { label: "备注", name: "Description", width: 200, align: "left", sortable: false }
            ],           
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100, 500, 1000],
            pager: "#gridPager",
            sortname: 'CreateDate desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (rowid) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件设置
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            SearchEvent()
        });
        //查询回车事件
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                SearchEvent();
            }
        });
    }
    //查询表格函数
    function SearchEvent() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["Type"] = _type;
        queryJson["TypeId"] = _typeid;
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../FinancialManage/FeeItems/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            page: 1
        }).trigger('reloadGrid');
    }

    //新增
    function btn_add() {
            dialogOpen({
                id: "Form",
                title: '新增费项',
                url: '/FinancialManage/FeeItems/Form',
                width: "1100px",
                height: "800px",
                btn: null,
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });       
    }
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑费项',
                url: '/FinancialManage/FeeItems/Form?keyValue=' + keyValue,
                width: "1100px",
                height: "800px",
                btn:null,
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: '/FinancialManage/FeeItems/RemoveForm',
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的会员！', 0);
        }
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" >
            <div id="itemTree"></div>
        </div>       
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编码</a></li>
                                        <li><a data-value="Name">名称</a></li>                                     
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询的名称或者编号" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div> 
   
</div>
